package cn.faster.common.exception;

import cn.faster.common.enums.CodeEnum;
import cn.faster.common.result.ResultBean;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * description: ShiroExceptionHandler
 * date: 2021/6/17 15:44
 * author: XiaoCoder
 * version: 1.0
 */
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ShiroExceptionHandler {

    @ExceptionHandler(UnauthenticatedException.class)
    public ResultBean<String> unauthenticatedExceptionHandler() {
        return ResultBean.ERROR(CodeEnum.ACCESS_UNAUTHORIZED);
    }

    @ExceptionHandler(UnauthorizedException.class)
    public ResultBean<String> unauthorizedExceptionHandler() {
        return ResultBean.ERROR(CodeEnum.ACCESS_UNAUTHORIZED);
    }

    @ExceptionHandler(AuthenticationException.class)
    public ResultBean<String> authenticationExceptionHandler() {
        return ResultBean.ERROR(CodeEnum.ACCESS_UNAUTHORIZED);
    }

}

